﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Maticsoft.DBUtility;

namespace ElingOA6_DSJCJ.DAL
{
    /// <summary>
    /// 信息投票数据类
    /// </summary>
    public class DocVote
    {
        public DocVote()
        {
        }
        /// <summary>
        /// 增加一条数据
        /// <creator>wangl</creator>
        /// <date>2013-09-11</date>
        /// </summary>
        public void Add(Model.DocVote model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into dbo.t_docVote(");
            strSql.Append("FDocId,FVoteIP,FVoteDate,FEntityNo,FEmplNo)");
            strSql.Append(" values (");
            strSql.Append("@FDocId,@FVoteIP,@FVoteDate,@FEntityNo,@FEmplNo)");
            SqlParameter[] parameters = {
					new SqlParameter("@FDocId", SqlDbType.Decimal,9),
					new SqlParameter("@FVoteIP", SqlDbType.NVarChar,15),
					new SqlParameter("@FVoteDate", SqlDbType.DateTime),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)};
            parameters[0].Value = model.FDocId;
            parameters[1].Value = model.FVoteIP;
            parameters[2].Value = model.FVoteDate;
            parameters[3].Value = model.FEntityNo;
            parameters[4].Value = model.FEmplNo;

            DbHelperSQL.GetSingle(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 是否存在该记录
        /// <creator>wangl</creator>
        /// <date>2013-09-11</date>
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <param name="emplNo">员工编号</param>
        /// <returns>是否存在</returns>
        public bool Exists(string entityNo, string emplNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from dbo.t_docVote");
            strSql.Append(" where FEntityNo=@FEntityNo and FEmplNo=@FEmplNo AND MONTH(FVoteDate)=MONTH(GETDATE())");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15),
                    new SqlParameter("@FVoteIP", SqlDbType.NVarChar,15),                    
                                        };
            parameters[0].Value = entityNo;
            parameters[1].Value = emplNo;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }
    }
}
